Completed
Push — master ( 194b5d...9967e2 )
by Ahmad
07:13
created

room.js ➔ showUpdateRoom   B

Complexity

Conditions 6

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
c 0
b 0
f 0
dl 0
loc 30
rs 8.5166
eloc 19
1
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
2
//
3
// Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
4
//
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU Lesser General Public License as published by the Free Software
7
// Foundation; either version 3.0 of the License, or (at your option) any later
8
// version.
9
//
10
// BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
13
//
14
// You should have received a copy of the GNU Lesser General Public License along
15
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
16
17
// Room specific js for copy button and email link.
18
$(document).on('turbolinks:load', function(){
19
  var controller = $("body").data('controller');
20
  var action = $("body").data('action');
21
22
  // Only run on room pages.
23
  if (controller == "rooms" && action == "show"){
24
    var copy = $('#copy');
25
26
    // Handle copy button.
27
    copy.on('click', function(){
28
      var inviteURL = $('#invite-url');
29
      inviteURL.select();
30
31
      var success = document.execCommand("copy");
32
      if (success) {
33
        inviteURL.blur();
34
        copy.addClass('btn-success');
35
        copy.html("<i class='fas fa-check'></i>" + getLocalizedString("copied"))
36
        setTimeout(function(){
37
          copy.removeClass('btn-success');
38
          copy.html("<i class='fas fa-copy'></i>" + getLocalizedString("copy"))
39
        }, 2000)
40
      }
41
    });
42
43
    // Forces the wrapper to take the entire screen height if the user can't create rooms
44
    if ($("#cant-create-room-wrapper").length){
45
      $(".wrapper").css('height', '100%').css('height', '-=130px');
46
    }
47
48
    // Display and update all fields related to creating a room in the createRoomModal
49
    $("#create-room-block").click(function(){
50
      showCreateRoom(this)
51
    })
52
53
    // Display and update all fields related to creating a room in the createRoomModal
54
    $(".update-room").click(function(){
55
      showUpdateRoom(this)
56
    })
57
  }
58
});
59
60
function showCreateRoom(target) {
61
  var modal = $(target)
0 ignored issues
show
Unused Code introduced by
The variable modal seems to be never used. Consider removing it.
Loading history...
62
  $("#create-room-name").val("")
63
  $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
64
  $("#room_access_code").val(null)
65
66
  $("#createRoomModal form").attr("action", $("body").data('relative-root'))
67
  $("#room_mute_on_join").prop("checked", false)
68
  $("#room_require_moderator_approval").prop("checked", false)
69
  $("#room_anyone_can_start").prop("checked", false)
70
  $("#room_all_join_moderator").prop("checked", false)
71
72
  //show all elements & their children with a create-only class
73
  $(".create-only").each(function() {
74
    $(this).show()
75
    if($(this).children().length > 0) { $(this).children().show() }
76
  })
77
78
  //hide all elements & their children with a update-only class
79
  $(".update-only").each(function() {
80
    $(this).attr('style',"display:none !important")
81
    if($(this).children().length > 0) { $(this).children().attr('style',"display:none !important") }
82
  })
83
}
84
85
function showUpdateRoom(target) {
86
  var modal = $(target)
87
  var room_block_uid = modal.closest("#room-block").data("room-uid")
88
  $("#create-room-name").val(modal.closest("tbody").find("#room-name h4").text())
89
  $("#createRoomModal form").attr("action", room_block_uid + "/update_settings")
90
91
  //show all elements & their children with a update-only class
92
  $(".update-only").each(function() {
93
    $(this).show()
94
    if($(this).children().length > 0) { $(this).children().show() }
95
  })
96
97
  //hide all elements & their children with a create-only class
98
  $(".create-only").each(function() {
99
    $(this).attr('style',"display:none !important")
100
    if($(this).children().length > 0) { $(this).children().attr('style',"display:none !important") }
101
  })
102
103
  updateCurrentSettings(modal.closest("#room-block").data("room-settings"))
104
  
105
  var accessCode = modal.closest("#room-block").data("room-access-code")
106
107
  if(accessCode){
108
    $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code") + ": " + accessCode)
109
    $("#room_access_code").val(accessCode)
110
  } else {
111
    $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
112
    $("#room_access_code").val(null)
113
  }
114
}
115
116
//Update the createRoomModal to show the correct current settings
117
function updateCurrentSettings(settings){
118
  //set checkbox
119
  $("#room_mute_on_join").prop("checked", settings.muteOnStart)
120
  $("#room_require_moderator_approval").prop("checked", settings.requireModeratorApproval)
121
  $("#room_anyone_can_start").prop("checked", settings.anyoneCanStart)
122
  $("#room_all_join_moderator").prop("checked", settings.joinModerator)
123
}
124
125
function generateAccessCode(){
126
  const accessCodeLength = 6
127
  var validCharacters = "0123456789"
128
  var accessCode = ""
129
130
  for( var i = 0; i < accessCodeLength; i++){
131
    accessCode += validCharacters.charAt(Math.floor(Math.random() * validCharacters.length));
132
  }
133
134
  $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code") + ": " + accessCode)
135
  $("#room_access_code").val(accessCode)
136
}
137
138
function ResetAccessCode(){
139
  $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
140
  $("#room_access_code").val(null)
141
}
142